using System.Windows.Data;
using System;

namespace HardToolApp.Tool
{
	public class Enum2Int : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter,
							  System.Globalization.CultureInfo culture)
		{
			int returnValue = 0;
			if (parameter is Type)
			{
				returnValue = (int)Enum.Parse((Type)parameter, value.ToString());
			}
			return returnValue;
			
		}

		public object ConvertBack(object value, Type targetType, object parameter,
								  System.Globalization.CultureInfo culture)
		{
			Enum enumValue = default(Enum);
			if (parameter is Type)
			{
				enumValue = (Enum)Enum.Parse((Type)parameter, value.ToString());
			}
			return enumValue;
		}
	}
}